package me.learningandroid.ch2_7.uicomponentdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.ToggleButton;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class Splash5Activity extends AppCompatActivity {

    public static void startActivity(Context context) {
        Intent intent = new Intent(context, Splash5Activity.class);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash5);

        TableLayout tableLayout = findViewById(R.id.tableLayoutDemoRoot);
        ToggleButton stretchBtn = findViewById(R.id.stretchBtn);
        ToggleButton shrinkBtn = findViewById(R.id.shrinkBtn);
        ToggleButton collapseBtn = findViewById(R.id.collapseBtn);

        stretchBtn.setOnCheckedChangeListener((v,checked) -> {
            for (int i=0; i<5; ++i) {
                // `TableLayout.setColumnStretchable`让第i列可扩展。当行宽度不足父组件宽度时，会拉伸可拉伸的列。
                tableLayout.setColumnStretchable(i,checked);
            }
        });
        shrinkBtn.setOnCheckedChangeListener((v,checked) -> {
            for (int i=5; i<7; ++i) {
                // `TableLayout.setColumnShrinkable`让第i列可收缩。当行宽度超过父组件限制时，会压缩可压缩列。
                tableLayout.setColumnShrinkable(i,checked);
            }
        });
        collapseBtn.setOnCheckedChangeListener((v,checked) -> {
            for (int i=5; i<7; ++i) {
                // `TableLayout.setColumnCollapsed`让第i列隐藏。
                // 如果跨行的列（指定了`layout_span`的列），占用了该列，也会隐藏。
                tableLayout.setColumnCollapsed(i,checked);
            }
        });


        FloatingActionButton nextBtn = findViewById(R.id.nextBtn);
        nextBtn.setOnClickListener((view)-> {
            Splash6Activity.startActivity(this);
        });
    }
}